package com.stream.demo;

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;

@EnableBinding(MyProcess.class)
public class MqConfig {

    /**
     * 接收所有的通道为input1Changel的消息
     * @param content
     */
    @StreamListener(target = "input1Changel" ,condition = "headers['type']=='foo'")
    public void input1Changel(Message<String> content){
        System.out.println("【input1Changel】接收到了消息："+content);
    }

    /**
     * 接收所有的通道为input2Changel的消息
     * 通过condition来实现数据的分区
     * @param content
     */
    @StreamListener(target = "input2Changel" ,condition = "headers['type']=='foo'")
    public void input2Changel(Message<String> content){
        System.out.println("【input2Changel】接收到了消息："+content);
    }

    /**
     * 接收所有的通道为input3Changel的消息,只有header中包含foo的消息才会被此监听接收
     * @param content
     */
    @StreamListener(target = "input3Changel" ,condition = "headers['type']=='foo'")
    public void input3Changel(Message<String> content){
        System.out.println("【input3Changel】接收到了消息："+content);
    }


}
